package com.younion.action.consumer.impl;

import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IMemberCardService;
import com.younion.model.MyCardInfoGetResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.vo.MemberCardVO;

public class MyCardInfoGetConsumer extends AbstractRequestConsumer {

	private IMemberCardService memberCardService;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getMyCardInfo(request, response);
	}

	public String getMyCardInfo(HttpServletRequest request,
			HttpServletResponse response) {
		MyCardInfoGetResult mycardInfoResult = new MyCardInfoGetResult();
		String card_id = request.getParameter("card_id");
		MemberCardVO memberCardVO = new MemberCardVO();
		ResultObject resultObject = new ResultObject();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			memberCardVO = memberCardService.getById(card_id);
			if(memberCardVO!=null){
				mycardInfoResult.setId(memberCardVO.getId().toString());
				mycardInfoResult.setMembeIdCard(memberCardVO.getMembeIdCard()!=null?memberCardVO.getMembeIdCard():"");
				mycardInfoResult.setMemberAddress(memberCardVO.getMemberAddress()!=null?memberCardVO.getMemberAddress():"");
				mycardInfoResult.setMemberBirth(memberCardVO.getMemberBirth()!=null?sdf.format(memberCardVO.getMemberBirth()):"");
				mycardInfoResult.setMemberEmail(memberCardVO.getMemberEmail()!=null?memberCardVO.getMemberEmail():"");
				mycardInfoResult.setMemberName(memberCardVO.getMemberName()!=null?memberCardVO.getMemberName():"");
				mycardInfoResult.setMemberPhone(memberCardVO.getMemberPhone()!=null?memberCardVO.getMemberPhone():"");
				mycardInfoResult.setMemberQq(memberCardVO.getMemberQq()!=null?memberCardVO.getMemberQq():"");
				mycardInfoResult.setMemberSex(memberCardVO.getMemberSex().toString());
				mycardInfoResult.setIsAllowPush(memberCardVO.getIsAllowPush().toString());
			}
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);

		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		resultObject.setResult(mycardInfoResult);
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setMemberCardService(IMemberCardService memberCardService) {
		this.memberCardService = memberCardService;
	}
}
